<?php
$path = "../";
include_once($path.'configuration.php');
/*traitements*/
include_once($path.'head.php');

if(isset($_GET['action']))
	$action = $_GET['action'];
else
	$action='add';

if($action=="add"){
	if(isset($_POST) && isset($_POST['submit']) && $_POST['submit'] != ''){
		extract($_POST);
		if(isset($nom) && $nom != '' && isset($salle) && $salle != '' && isset($ip) && $ip != ''){
			$machine = new machine($dbh);
			$machine->setNom($nom);
			$machine->setIp($ip);
			$machine->setSalle($salle);
			$machine->save();
			header('Location: '.$path . 'administration/gestion_machine.php');
			exit;
		}else{
			$message = "Veuillez remplir tous les champs obligatoires !";
		}
	}
}elseif($action == "modif"){
	if(isset($_GET) && isset($_GET['machine']) && $_GET['machine'] != 0){
		if(isset($_POST) && isset($_POST['submit']) && $_POST['submit'] != ''){
			extract($_POST);

			if(isset($nom) && $nom != '' && isset($salle) && $salle != '' && isset($ip) && $ip != ''){
				$user = new machine($dbh, $_GET['machine']);
				$user->setNom($nom);
				$user->setIp($ip);
				$user->setSalle($salle);
				$user->save();

				header('Location: '.$path . 'administration/gestion_machine.php');
			}else{
				$message = "Veuillez remplir tous les champs obligatoires !";
			}
			
		}
	}	
}
elseif($action == "delete"){
	if(isset($_GET) && isset($_GET['machine']) && $_GET['machine'] != 0){
		$machine = new machine($dbh, $_GET['machine']);
		$machine->delete();
		header('Location: '.$path .'administration/gestion_machine.php');
	}
}

	
if($action == "modif"){
	if(isset($_GET) && isset($_GET['machine']) && $_GET['machine'] != 0){
		$user = new machine($dbh, $_GET['machine']);
		$nom = $user->getNom();
		$ip = $user->getIp();
		$salle = $user->getSalle();
	}
}
?>

<div id="bodyWrapper">
	<form method="post" id="form" action="">
		<p>
			<label for="name" class="label">Nom* :</label> <input type="text"
				id="nom" name="nom" class="input"
				value="<?php if(isset($nom)) echo $nom;?>" />
		</p>

		<p>
			<label for="salle" class="label">salle* :</label> <input type="text"
				id="salle" name="salle" class="input"
				value="<?php if(isset($salle)) echo $salle;?>" />
		</p>
		<p>
			<label for="ip" class="label">IP* :</label> <input type="text"
				id="ip" name="ip" class="input"
				value="<?php if(isset($ip)) echo $ip;?>" />
		</p>
		<p>
			<input type="submit" name="submit" id="submit" class="input"
				value="Envoyer" />
		
		
		<p>
			<input class="input" name="reset" type=reset>
		</p>
	</form>
</div>
<?php
include_once($path.'footer.php');
?>